using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class MemberIdeaMessageDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public MemberIdeaMessageDA()
		{
		}

		public MemberIdeaMessageDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the MemberIdeaMessage table.
		/// </summary>
		public  int Insert(MemberIdeaMessage memberIdeaMessage)
		{
			ValidationUtility.ValidateArgument("memberIdeaMessage", memberIdeaMessage);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", memberIdeaMessage.ProfileID),
				new SqlParameter("@TenantID", memberIdeaMessage.TenantID),
				new SqlParameter("@IdeaID", memberIdeaMessage.IdeaID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberIdeaMessageInsert", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberIdeaMessage table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberIdeaMessageDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Selects all records from the MemberIdeaMessage table.
		/// </summary>
		public  List<MemberIdeaMessage> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberIdeaMessageSelectAll", parameters))
			{
				List<MemberIdeaMessage> memberIdeaMessageList = new List<MemberIdeaMessage>();
				while (dataReader.Read())
				{
					MemberIdeaMessage memberIdeaMessage = MakeMemberIdeaMessage(dataReader);
					memberIdeaMessageList.Add(memberIdeaMessage);
				}

				return memberIdeaMessageList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberIdeaMessage table by a foreign key.
		/// </summary>
		public  List<MemberIdeaMessage> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberIdeaMessageSelectAllByProfileID", parameters))
			{
				List<MemberIdeaMessage> memberIdeaMessageList = new List<MemberIdeaMessage>();
				while (dataReader.Read())
				{
					MemberIdeaMessage memberIdeaMessage = MakeMemberIdeaMessage(dataReader);
					memberIdeaMessageList.Add(memberIdeaMessage);
				}

				return memberIdeaMessageList;
			}
		}

		/// <summary>
		/// Creates a new instance of the MemberIdeaMessage class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  MemberIdeaMessage MakeMemberIdeaMessage(SqlDataReader dataReader)
		{
			MemberIdeaMessage memberIdeaMessage = new MemberIdeaMessage();
			memberIdeaMessage.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			memberIdeaMessage.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			memberIdeaMessage.IdeaID = SqlClientUtility.GetInt32(dataReader, "IdeaID", 0);

			return memberIdeaMessage;
		}

		#endregion
	}
}
